# -*- coding: utf-8 -*-

import pandas as pd
from pipe.readExcel import exportExcel
import csv

def readTxt(filepath):
    # df = pd.read_csv(filepath,names=['col1'],header=None,quoting=csv.QUOTE_NONE) # 获取日期数据
    df = pd.read_csv(filepath,header=None) # 获取日期数据
    return df

# print(df)
def spiltTxt(filepath,excelName):
    df = readTxt(filepath)
    # print(df)
    result=[]
    a = []
    for ii in df.index:
        print('---------------',ii)
        print(df.iloc[ii])
        if (ii != 0 and ii % 13 !=0):
           a.append(ii)
        else:
            if ii != 0:
                a.append(ii)
                result.append(a)
                a = []
    # print(result)
    # print(df.iloc(result))

    dfs=[]
    for i in result:
        # print(i)
        df1=df[i[0]:i[len(i)-1]]
        # print(df1.T)
        df2=df1.T
        df2.columns = ['发电客户名称','接入电网','项目名称','能源类型','并网规模(KW)','全部机组并网时间','电价类型','上网电价(含税)(元/千瓦时)','列入规模管理年限(年)','业务类型','纳入目录时间','纳入目录批次']
        # df2.columns = ['序号','发电客户名称','接入电网','项目名称','能源类型','并网规模(KW)','全部机组并网时间','电价类型','上网电价(含税)(元/千瓦时)','列入规模管理年限(年)','业务类型','纳入目录时间','纳入目录批次']
        dfs.append(df2)
        # print(df2)
    # print(dfs)
    df3=pd.concat(dfs)
    # print(df3)
    exportExcel(filepath,df3,excelName)

        # print(ii)
        # date_time = df.loc[ii].values
        # print(date_time)

if __name__ == '__main__':
    filepath=r'E:\下载\转Excel.txt'
    # filepath = r'E:\下载\转Excel.txt'
    # filepath = r'E:\项目相关\13.可再生能源补贴\殷甲伟\可再生能源项目政策文件\新能源云\非自然人分布式\非自然人分布式补贴清单_规律13项.txt'

    spiltTxt(filepath,"合并数据")


